<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@include file="/common/common.jspf"%>
<script type="text/javascript" src="${ctx}/js/system/user/edit.js"></script>
<script type="text/javascript" src="${ctx}/js/system/user/productChild.js"></script>
<style type="text/css">
.col-sm-3 {
	width: 15%;
	float: left;
}
.col-sm-9 {
	width: 32%;
	float: left;
}


.col-sm-31 {
	position: relative;
	width: 15%;
	float: left;
	top: 8px;
	text-align: right;
}

.col-sm-91 {
	width: 35%;
	float: left;
	text-align: left;
}
</style>
</head>
<body>
	<div class="l_err" style="width: 100%; margin-top: 2px;"></div>
	<form id="form" name="form" class="form-horizontal" method="post"
		  action="${ctx}/product/editProduct.shtml">
		<input type="hidden" class="form-control" value="${user.itemId}"
			   name="productFormMap.itemId" id="itemId">
		<section class="panel panel-default">
			<div class="panel-body">
				<div class="form-group">
					<div class="col-sm-3">
						<label class="control-label">产品编号</label>
					</div>
					<div class="col-sm-9">
						<input type="text" class="form-control"
							   name="productFormMap.itemCode" id="itemCode" value="${user.itemCode}">

					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">产品名称</label>
						<div class="col-sm-9">
							<input type="text" class="form-control"
								   name="productFormMap.itemName"
								   id="itemName" value="${user.itemName}">
						</div>
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-3 control-label">产品规格</label>
					<div class="col-sm-9">
						<input type="text" class="form-control"
							   name="productFormMap.itemSpec"
							   id="itemSpec" value="${user.itemName}">
					</div>

					<div class="form-group">
						<label class="col-sm-3 control-label">产品单位</label>
						<div class="col-sm-9">
							<select class="form-control" name="productFormMap.unitId" id="unitId">
								<c:if test="${user.unitId eq 1}">
									<option value="1" selected>条</option>
									<option value="2">克</option>
									<option value="3">KG</option>
									<option value="4">台</option>
									<option value="5">个</option>
								</c:if>

								<c:if test="${user.unitId eq 2}">
									<option value="1" >条</option>
									<option value="2" selected>克</option>
									<option value="3">KG</option>
									<option value="4">台</option>
									<option value="5">个</option>
								</c:if>

								<c:if test="${user.unitId eq 3}">
									<option value="1" >条</option>
									<option value="2" >克</option>
									<option value="3" selected>KG</option>
									<option value="4">台</option>
									<option value="5">个</option>
								</c:if>

								<c:if test="${user.unitId eq 4}">
									<option value="1" >条</option>
									<option value="2">克</option>
									<option value="3" >KG</option>
									<option value="4" selected>台</option>
									<option value="5">个</option>
								</c:if>

								<c:if test="${user.unitId eq 5}">
									<option value="1" >条</option>
									<option value="2">克</option>
									<option value="3">KG</option>
									<option value="4">台</option>
									<option value="5" selected>个</option>
								</c:if>

							</select>
						</div>
					</div>
				</div>


				<div class="form-group">
					<label class="col-sm-3 control-label">产品产地</label>
					<div class="col-sm-9">
						<input type="text" class="form-control"
							   name="productFormMap.itemArea"
							   id="itemArea" value="${user.itemArea}">
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">产品类别</label>
						<div class="col-sm-9">
							<select class="form-control" name="productFormMap.itemTypeId" id="itemTypeId">
								<c:if test="${user.itemTypeId eq 2}">
									<option value="2" selected>Beckhoff</option>
									<option value="3">Baumueller包米勒</option>
									<option value="5">合耕科技有限公司</option>
									<option value="6">空调配件有限公司</option>
								</c:if>

								<c:if test="${user.itemTypeId eq 3}">
									<option value="2" >Beckhoff</option>
									<option value="3" selected>Baumueller包米勒</option>
									<option value="5">合耕科技有限公司</option>
									<option value="6">空调配件有限公司</option>
								</c:if>

								<c:if test="${user.itemTypeId eq 5}">
									<option value="2" >Beckhoff</option>
									<option value="3">Baumueller包米勒</option>
									<option value="5" selected>合耕科技有限公司</option>
									<option value="6">空调配件有限公司</option>
								</c:if>

								<c:if test="${user.itemTypeId eq 6}">
									<option value="2" >Beckhoff</option>
									<option value="3">Baumueller包米勒</option>
									<option value="5">合耕科技有限公司</option>
									<option value="6" selected>空调配件有限公司</option>
								</c:if>

							</select>
						</div>
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-3 control-label">产品价格</label>
					<div class="col-sm-9">
						<input type="text" class="form-control checkacc"
							   name="productFormMap.itemPrice"
							   id="itemPrice" value="${user.itemPrice}">
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">供应商</label>
						<div class="col-sm-9">
							<select class="form-control" name="productFormMap.clientId" id="clientId">
								<option value="2">Beckhoff</option>
								<option value="3">Baumueller包米勒</option>
								<option value="4">展会观众</option>
								<option value="5">合耕科技有限公司</option>
								<option value="6">空调配件有限公司</option>
							</select>
						</div>
					</div>
				</div>
				<div class="line line-dashed line-lg pull-in"></div>
				<footer class="panel-footer text-right bg-light lter">
					<button type="submit" class="btn btn-success btn-s-xs">提交</button>
				</footer>
		</section>
	</form>
	<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">添加</button>
	<button type="button" class="btn btn-primary" onclick="edit()">修改</button>
	<button type="button" class="btn btn-primary" id="del">删除</button>
	<div id="paging" class="pagclass"></div>
	<!-- Button trigger modal -->


	<!-- Modal -->
	<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" id="myModal">
		<div class="modal-dialog modal-sm" role="document">
			<div class="modal-content" style="height: 150px">
				<div style="height: 20px"></div>
				<div  class="form-horizontal">
					<input type="hidden" class="form-control" value="${user.itemId}"
						   name="stocktomat.stockid" id="stockid">
				<div class="form-group">
					<div class="col-sm-31">
						<label class="control-label">物料选择&nbsp;&nbsp;</label>
					</div>
					<div class="col-sm-91">
						<select class="form-control" name="stocktomat.matid" id="matid">
							<option value="1">网线</option>
							<option value="2">路由</option>
							<option value="3">筷子</option>
							<option value="4">勺子</option>
							<option value="5">盒子</option>
							<option value="6">触摸屏</option>
						</select>
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-31">
						<label class="control-label">数量&nbsp;&nbsp;</label>
					</div>
					<div class="col-sm-91">
						<input type="text" class="form-control"
							   name="stocktomat.stmnum" id="stmnum">
					</div>
				</div>
					<div class="line line-dashed line-lg pull-in"></div>
					<footer class="panel-footer text-right bg-light lter">
						<button  class="btn btn-default" name="save" onclick="sub()">提交</button>
						<button type="button" class="btn btn-default" data-dismiss="modal" id="close" >关闭</button>
					</footer>
					</div>
			</div>

		</div>
	</div>
	<script type="text/javascript">
		onloadurl();
		var flag = false;//true修改，false为添加
		function sub() {

			if(flag){
				$.ajax({
					url: "${ctx}/product/editChild.shtml",
					data: {'stocktomat.stockid': $("#stockid").val(),"stocktomat.matid": $("#matid").val(),"stocktomat.stmnum": $("#stmnum").val()},
					type: "POST",
					dataType: "json",
					success: function () {
						var r = confirm("是否关闭");
						if (r == true) {
							$('#myModal').modal('hide');
							grid.loadData();
							flag = false;

						} else {
						}

					}
				})
			}else {
				$.ajax({
					url: "${ctx}/product/addChild.shtml",
					data: {'stocktomat.stockid': $("#stockid").val(),"stocktomat.matid": $("#matid").val(),"stocktomat.stmnum": $("#stmnum").val()},
					type: "POST",
					dataType: "json",
					success: function () {
						var r = confirm("是否关闭");
						if (r == true) {
							$('#myModal').modal('hide');
							grid.loadData();
						} else {
						}

					}
				})
			}
		}

		function edit() {
			var cbox = grid.getSelectedCheckbox();
			if (cbox.length > 1 || cbox == "") {
				layer.msg("只能选中一个");
				return;
			}
			$('#myModal').modal('show');
			var row = grid.selectRow();
			var temp = row[0].matid;
			$("#matid").find("option[value="+temp+"]").attr("selected",true);
			$("#stmnum").val(row[0].stmnum);
			$("#matid").attr("disabled","disabled");
			flag = true;
		}

		$("#del").click(function () {
			var row = grid.getSelectedCheckbox();
			var temp = row.join(",");
			//将数据连接起来
			$.ajax({
				url: "${ctx}/product/deleteChild.shtml",
				data: {'stocktomat.matid': temp,'stocktomat.stockid': $("#itemId").val()},
				type: "POST",
				dataType: "json",
				success: function () {
					var r = confirm("是否关闭");
					if (r == true) {
						$('#myModal').modal('hide');
						grid.loadData();
						flag = false;
					} else {
					}
				}
			})
		});

		$("#close").click(function () {
			$("#matid").find("option[value= '1']").attr("selected",true);
			$("#stmnum").val("");
			$("#matid").removeAttr("disabled");
		});

	</script>
</body>
</html>